//
//  HYFStatusCell.m
//  MyOCWeibo
//
//  Created by 黄勇锋 on 16/10/8.
//  Copyright © 2016年 黄勇锋. All rights reserved.
//

#import "HYFStatusCell.h"
#import "HYFStates.h"
#import "HYFStatusToolBar.h"


@interface HYFStatusCell()

@property (weak,nonatomic) UIImageView *headImageView;
@property (weak, nonatomic) UILabel *nameLabel;
@property (weak, nonatomic) UILabel *timeLabel;
@property (weak, nonatomic) UILabel *sourceLabel;
//原创微博文字
@property (weak, nonatomic) UILabel *contentLabel;
//原创微博配图
@property (weak, nonatomic) UIImageView *originalImageView;
//工具条
@property (weak, nonatomic) HYFStatusToolBar *toolBar;

@end


@implementation HYFStatusCell

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    HYFStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:HYFStatusCellID];
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //添加子控件
        //1.添加原创微博
        [self addOriginalView];
        //2.添加转发微博内容
       
        
        //3.添加底部的工具条
        HYFStatusToolBar *toolBar = [[HYFStatusToolBar alloc]init];
        [self.contentView addSubview:toolBar];
        self.toolBar = toolBar;
        
    }
    
    return self;
}

//添加原创微博内容
- (void)addOriginalView{
    
    //头像
    UIImageView *headImageView = [[UIImageView alloc]init];
    self.headImageView = headImageView;
    [self.contentView addSubview:headImageView];
    
    //昵称
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.font = SYS_FONT(NAME_LABEL_FONT);
    self.nameLabel = nameLabel;
    [self.contentView addSubview:nameLabel];
    
    UILabel *timeLabel = [[UILabel alloc]init];
    timeLabel.font = SYS_FONT(TIME_LABEL_FONT);
    self.timeLabel = timeLabel;
    [self.contentView addSubview:timeLabel];
    
    UILabel *sourceLabel = [[UILabel alloc]init];
    sourceLabel.font = SYS_FONT(TIME_LABEL_FONT);
    self.sourceLabel = sourceLabel;
    [self.contentView addSubview:sourceLabel];
    
    UILabel *contentLabel = [[UILabel alloc]init];
    contentLabel.font = SYS_FONT(CONTENT_LABEL_FONT);
    contentLabel.numberOfLines = 0;
    self.contentLabel = contentLabel;
    [self.contentView addSubview:contentLabel];
    
    UIImageView *originalImageView = [[UIImageView alloc]init];
    self.originalImageView = originalImageView;
    [self.contentView addSubview:originalImageView];
    
}


- (void)setStatesFrame:(HYFStatusFrame *)statesFrame{
    
    _statesFrame = statesFrame;
    
    HYFStates *states = statesFrame.states;
    
    //设置头像
    self.headImageView.frame = statesFrame.headImageViewF;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:states.user.profile_image_url] placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
    
    //设置昵称
    self.nameLabel.frame = statesFrame.nameLabelF;
    self.nameLabel.text = statesFrame.states.user.screen_name;
    
    //设置时间
    self.timeLabel.frame = statesFrame.timeLabelF;
    self.timeLabel.text = statesFrame.states.created_at;
    
    //设置来源
    self.sourceLabel.frame = statesFrame.sourceLabelF;
    self.sourceLabel.text = statesFrame.states.source;
    
    //设置内容
    self.contentLabel.frame = statesFrame.contentLabelF;
    self.contentLabel.text =  statesFrame.states.text;
    
    
    //cell 是可以复用的. 如果没有图片,那么就不能复用,所以,要隐藏.  在 cell 里面,只要有 if ,必须要有 else
    if (statesFrame.states.thumbnail_pic) {
        
        //以防止复用出错,显示不出来!
        self.originalImageView.hidden = NO;
        
        self.originalImageView.frame = statesFrame.originalImageViewF;
        
        [self.originalImageView sd_setImageWithURL:[NSURL URLWithString:states.thumbnail_pic] placeholderImage:[UIImage imageNamed:@"timeline_image_placeholder"]];
        
    }else{
        
         //以防止复用出错,没有图片的微博也显示图片.
        self.originalImageView.hidden = YES;
    }
    
    //设置工具条的 frame
    self.toolBar.frame = statesFrame.toolBarF;
    
     
}



@end
